import java.util.*;
import java.awt.Point;

public class Group extends HashSet<Card> {
	
	public Group(Collection<Card> initial) {
		super(initial);
	}
	public Group(Card initial) {
		super();
		this.add(initial);
	}
	public Group() {
		super();
	}
	
	public void shuffle() {
		Set<Card> shuffledSet = new HashSet<Card>();
		
		ArrayList<Integer> zedvalues = new ArrayList<Integer>();
		ArrayList<Point> points = new ArrayList<Point>();
		int numCardsInGroup = 0;
		
		for(Card c: this) {
			zedvalues.add(c.getZ());
			points.add(c.getLocation());
			numCardsInGroup++;
			shuffledSet.add(c);			
		}
		
		int[] newOrder = randomPermute(numCardsInGroup);
		
		int index = 0;
		
		for(Card c2: shuffledSet) {
			c2.setLocation(points.get(newOrder[index]));
			c2.setZ(zedvalues.get(newOrder[index]));
			index++;
		}
	}
	
	private int[] randomPermute(int max) {
		ArrayList<Integer> unused = new ArrayList<Integer>();
		for (int i = 0; i < max; i++) {
			unused.add(i);
		}
		
		Random r = new Random();
		int[] order = new int[max];
		for (int i = 0; i < max; i++) {
			int chosen = r.nextInt(unused.size());
			order[i] = unused.get(chosen);
			unused.remove(chosen);
		}
		
		return order;
	}
/*	public void add(Card c) {
		
	}
	
	public void add(Group g) {
		
	}
	
	public Card remove(int cardID) {
		return null;
	}
	
	public Card[] remove(int[] cardIDs) {
		return null;
	}*/
	
	
	
}